package me.spring.cloud.common.components.validator.annotation.constraint;

import me.spring.cloud.common.components.validator.annotation.ObjectValid;
import me.spring.cloud.common.components.validator.util.BeanValidatorUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class ObjectValidator implements ConstraintValidator<ObjectValid,Object>{
	
	public boolean needValid;

	@Override
	public void initialize(ObjectValid constraint) {
		this.needValid = constraint.needValid();
	}
	
	@Override
	public boolean isValid(Object value, ConstraintValidatorContext context) {
		if(null != value && needValid) {
			BeanValidatorUtil.checkModelValidation(value);
		}
		return true;
	}

}
